require "test/unit"

require "stringio"
require "Logger"
require "Tokenizer"
require "Parser"

class TestParser < Test::Unit::TestCase
  def setup
    @log = Logger.new(STDOUT)
    @log.datetime_format = "%Y-%m-%d %H:%M:%S "
    @log.level = Logger::Severity::UNKNOWN
    
    @parser_tests = Dir.glob("./test/Parser/*.in")
  end
  
  def test_parser
    @parser_tests.each do| filename |
      filename.match('(.*)\.in')
      output = $1 + '.out'
      out_file = File.new(output)
      exp_output = out_file.read.chomp
    
      tok = Tokenizer.new(filename, @log)
      pars = Parser.new(tok, @log)
      assert_nothing_raised("Exception parsing file #{$1}.in") do
        e = pars.parse()
        assert_equal(exp_output, e.to_parenth_notation, "Error parsing file #{$1}.in")
      end
    end
  end

end